<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Company extends Admin_Controller
{
	private static $data = array();
    protected $models=['company_model','type_model','technician_model'];
	public function __construct()
	{
		parent::__construct();
	}

	//待审核
	public function issue0()
	{
	    self::$data['dataurl']=site_url('admin/company/getIssue0');
	    $this->load->view('admin/company/list.html',self::$data);
	}
	//审核通过
	public function issue1()
	{
	    self::$data['dataurl']=site_url('admin/company/getIssue1');
	    $this->load->view('admin/company/list.html',self::$data);
	}
	//审核被拒
	public function issue2()
	{
	    self::$data['dataurl']=site_url('admin/company/getIssue2');
	    $this->load->view('admin/company/list.html',self::$data);
	}
	
	public function getIssue0(){
	    $this->getList(0);
	}
	public function getIssue1(){
	    $this->getList(1);
	}
	public function getIssue2(){
	    $this->getList(2);
	}
	
	public function getList($issue){
	    $search=$this->input->get('search');
	    $page=$this->input->get('page');
	    $limit=$this->input->get('limit');
	    $page=$page-1;	    
	    $where=['is_delete'=>0,'issue'=>$issue];
	    
	    $count=$this->company_model->getWhere_num($where);
	    $company=$this->company_model->getWhere($where);
	    foreach ($company as $key=>$val){
	        $company[$key]['createTime']=format_time($val['createTime']);
	    }
	    
	    if($company){
	        show200_admin($company,$count);
	    }else{
	        show400_admin();
	    }
	}
	//获取店铺详情
	public function detail(){
	    $companyId=$this->input->get('id');
	    $company=$this->company_model->getWhereRow(['companyId'=>$companyId]);
	    $company['serviceTypeIds']=explode('|', $company['serviceTypeIds']);
	    $trade=$this->type_model->getWhere(['flag'=>1]);       //行业数据
	    $service=$this->type_model->getWhere(['flag'=>9]);     //服务数据
	    $technicianNum=$this->technician_model->getWhere_num(['companyId'=>$companyId,'is_delete'=>0]);
	    $company['technicianNum']=$technicianNum;
	    self::$data['company']=$company;
	    self::$data['trade']=$trade;
	    self::$data['service']=$service;
	    self::$data['adminFlag']=1;
	  
	    $this->load->view('seller/company/info.html',self::$data);
	}
	//通过审核
	public function able(){
	    $companyId=$this->input->post('companyId');
	    $res=$this->company_model->updateWhere(['companyId'=>$companyId],['issue'=>1]);
	    if($res){
	        show200_admin([],'','操作成功');
	    }else{
	        show400_admin('操作失败');
	    }
	}
	//拒绝通过审核
	public function disable(){
	    $companyId=$this->input->post('companyId');
	    $res=$this->company_model->updateWhere(['companyId'=>$companyId],['issue'=>2]);
	    if($res){
	        show200_admin([],'','操作成功');
	    }else{
	        show400_admin('操作失败');
	    }
	}
	//删除
	public function del(){
	    $companyId=$this->input->post('companyId');
	    $res=$this->company_model->del($companyId);
	    if($res){
	        show200_admin([],'','操作成功');
	    }else{
	        show400_admin('操作失败');
	    }
	}

//	设为m2
    public function setM2()
    {
        $companyId=$this->input->post('companyId');
        $row = $this->company_model->getOne($companyId);
        if(!empty($row) && $row['typeFlag'] == 'M2') {
            show400_admin('已经是M2用户');
        }
        $res=$this->company_model->setM2($companyId);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
}
/* End of file Login.php */